package nevo.test;

import java.util.*;

import org.junit.*;

import nevo.core.*;
import nevo.pkgs.expr.RealFunctionModel;
import nevo.pkgs.expr.RealObjectiveFunction;

public abstract class OptimizerTest1
{		
	protected abstract Optimizer setup();
	protected abstract int getMaxIterations();	
	protected abstract List< Map<String,Object> > getInitialGuesses();
	protected abstract double getExpectedResidual();
	
	@Test public void test1() throws Exception
	{
		Optimizer op = setup();
		RealFunctionModel model = new RealFunctionModel();
		model.setOutputName("y");
		model.setExpression("50-x^2");
		
		op.setModel(model);
		
		RealObjectiveFunction objfun = new RealObjectiveFunction();
		objfun.setExpression("abs(y)");
		op.setObjectiveFunction(objfun);
		op.setInitialGuesses(getInitialGuesses());		
				
		int numiter = Utilities.runOptimization(op, getExpectedResidual(), getMaxIterations());
		System.err.println("simpleFunction: " + op.getClass().getName() +
				           " took " + numiter + " iterations");
	}
	
}
